package com.ruoyi.business.config;//package com.config;


import com.ruoyi.business.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 添加拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor(stringRedisTemplate))
                .addPathPatterns("/**")
//                .addPathPatterns("/test")

                .excludePathPatterns(
        //不需要登录验证的接口放行，不需要拦截
                        "/business/roomInfo/**",
                        "/business/user/login",
                        "/business/user/register",
                        "/business/common2/upload2",
                        "/business/common2/download",
                        "/business/common2/moreUpload",
                        "/business/seller/login",
                        "/business/seller/register",
                        "/business/seller/list2",
                        "/business/homestayInfo/homepageRecommendation/**",
                        "/business/homestayInfo/refreshScore",

                        "/business/homestayInfo/homestaylist2",
                        "/business/homestayInfo/homepageRecommendation",
                        "/business/homestayInfo/getHomestayInfo/**",
                        "/business/homestayInfo/list",
                        "/business/homestayInfo/search",

                        "/features/list",



                        "/business/roomInfo/**",
                        "/business/featureType/**",
                        "/business/appAlipay/**",
                        "/business/comments/selectReply",
                        "/business/common2/downloadApp",
                        "/business/user/chatContent/getMyFriend",
                        "/business/user/chatContent/getMyFriend/**",

                        "/business/alipay/**",
                        "/business/alipay/notify",

                        "/business/roomInfo/**",
                        "/business/roomType/list",
                        "/business/comments/**",
                        "/business/couponInfo/selectCouponInfo",
//                        "buiness/user/payment",

                        "/business/user/chatContent/mySellers",
                        "/business/user/chatContent/chatRecords",
                        "/business/user/chatContent/getMyFriend",



                        //TODO 开发暂时允许访问
                 // swagger相关接口
                "/swagger-ui/**",
                "/swagger-ui.html",
                "/swagger-resources/**",
                "/doc.html"
                ).order(0);

//        // token刷新的拦截器
//        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**")
//                .order(0);//设置第一个拦截器，拦截所有请求刷新用
    }
}
